package morphage.engine;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageObserver;

public abstract class OperationLayer
{
  protected LayerData   m_layerData = null;
  
  public String         getName() { return "unknown"; }
  
  public void paintFirst( Graphics g, int width, int height, ImageObserver obs ) 
  {
    Image image = null;
    if( m_layerData == null )
      image = ImageManager.getFirstImage();
    else
    {
      assert( m_layerData.getFirstImage() != null );
      image = m_layerData.getFirstImage();
    }
    if( image != null )
      g.drawImage( image, 0, 0, width, height, obs );
    else
    {
      g.setColor( Color.WHITE );
      g.fillRect( 0, 0, width, height );
    }
  }
  public void paintLast( Graphics g, int width, int height, ImageObserver obs )  
  { 
    Image image = null;
    if( m_layerData == null )
      image = ImageManager.getLastImage();
    else
    {
      assert( m_layerData.getLastImage() != null );
      image = m_layerData.getLastImage();
    }
    if( image != null )
      g.drawImage( image, 0, 0, width, height, obs );
    else
    {
      g.setColor( Color.WHITE );
      g.fillRect( 0, 0, width, height );
    }
  }
  public void paintIntermediate( Graphics g, int width, int height, ImageObserver obs ) 
  { 
    Image image = null;
    if( m_layerData == null )
      image = ImageManager.getFirstImage();
    else
    {
      assert( m_layerData.getImage() != null );
      image = m_layerData.getImage();
      MatrixBufferedImage matImage = (MatrixBufferedImage)image;
      matImage.matrix2Image();
    }
    if( image != null )
      g.drawImage( image, 0, 0, width, height, obs );
    else
    {
      g.setColor( Color.WHITE );
      g.fillRect( 0, 0, width, height );
    }
  }
  public LayerData Compute(LayerData in)
  { 
    m_layerData = in;
    return in; 
  }
  public LayerData getData() { return m_layerData; }
}
